package middlewares

import (
	"gin-gorm-oj/helper"
	"github.com/gin-gonic/gin"
)

func AuthUserCheck() gin.HandlerFunc {
	return func(c *gin.Context) {
		auth := c.GetHeader("Authorization")

		userClaim, err := helper.AnalysisToken(auth)
		if err != nil || userClaim == nil {
			c.Abort()
			c.JSON(200, gin.H{
				"code": 401,
				"msg":  "Unauthorized",
			})
			return

		}
		c.Set("empId", userClaim.EmpId)
		c.Next()

	}
}
